package com.liyuhang.action;

import com.liyuhang.domain.User;
import com.liyuhang.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

public class LoginAction implements ModelDriven<User> {
    @Setter
    @Getter
    private User user = new User();

    private UserService userService = new UserService();

    public String login() {
        Map sessionMap=ActionContext.getContext().getSession();
        sessionMap.put("username",user.getUsername());
        sessionMap.put("password",user.getPassword());
        if (userService.login(user))
            return "success";
        return "error";
    }

    @Override
    public User getModel() {
        return user;
    }
}
